## -*- coding: utf-8 -*-
<%inherit file="/derived/blog/blog_base.html"/>
<%namespace file="/component/utils.html" import="*" />
<%namespace file="/component/post.html" import="blog_show, display_comments, blog_comments" />

<div class="blog_main">
    ${blog_show(c.post, True)}
    <div id="commentsWrapper" class="blog_comment">
        ${display_comments(c.comments)}
    </div>
    <div class="blog_comment">
        ${blog_comments()}        
    </div>
</div>

<%def name="head()">
${parent.head()}
${h.javascript_link(h.url_for('/js/nicEdit.js'))}

<script type="text/javascript">
    var comment_content;
    var contentTextArea;
    $(document).ready(function() {
        contentTextArea = new nicEditor({maxHeight : 200,
            iconsPath : "${h.url_for('/js/nicEditorIcons.gif')}",
            buttonList : ['bold','italic','underline','left','center','right','ol','ul','fontSize','indent','outdent','image','link','unlink','forecolor']
        }).panelInstance('content');

        $('#btnSubmit').click(commentAdd);
    });

    function commentAdd()  {
        var data = contentTextArea.nicInstances[0].getContent();
        if ('<br>' == data.toLowerCase()) {
            data = '';
        }
        if (data == '') {
            var l = $('<label class="error">请提供您的评论</label>');
            l.appendTo($('#commentErrorWrapper'));
            l.delay(3000, function() {
                l.remove();
            });
            return;
        }
        comment_content = data;
        contentTextArea.nicInstances[0].setContent('');
        $.post("/comment/create/${c.post.id}",
            {content:comment_content},
            commentAdded,
            "json");
    }

    function commentAdded(data, textStatus)  {
      if (data.flag == 1) {
          $('#comments').after(genCommentDiv(data, comment_content));
      } else {
          var l = $('<label class="error">' + data.info + '</label>');
          l.appendTo($('#commentErrorWrapper'));
          l.delay(3000, function() {
              l.remove();
          });
      }
    }

</script>
</%def>